package com.study;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringEscapeUtils;

import java.util.Set;

/**
 * Test13
 *
 * @author wanghuilong
 * @version 1.0
 * @description
 * @date 2023/3/2 15:45
 */
public class Test13 {


    public static void main(String[] args) {
        String str = "{\"biz_source\":\"C_TERMINAL_MALL\",\"main_account_code\":\"PTACT000000000004\",\"pay_channel\":\"wxpay_ecommerce\",\"entity_code\":\"whldfnxucgk\",\"entity_type\":1,\"out_request_no\":\"APPLYMENT_1444844335333376_202203011677653883_6\",\"organization_type\":\"2\",\"business_license_info\":{\"business_license_copy\":\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/062901cac8604728ae536bb4c703b6c390e1e76cf3222747b14ceace7d7deff1.png?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678334249&Signature=%2BeJAKa7IiNcdNd2JwuPA5A3cob0%3D&validTime=1678334249707&resId=1461870122631168\",\"business_license_number\":\"913301066623297023\",\"merchant_name\":\"杭州致民医药连锁有限公司\",\"legal_person\":\"陈坤\",\"company_address\":\"浙江省杭州市西湖区同人精华大厦2号楼1301、1302、1303、1304室\",\"business_time\":\"[\\\"2007-06-18\\\",\\\"2027-06-17\\\"]\"},\"organization_cert_info\":null,\"id_doc_type\":\"IDENTIFICATION_TYPE_MAINLAND_IDCARD\",\"owner\":true,\"id_card_info\":{\"id_card_copy\":\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/3f7f304cda5945fb96a5c4c18e34151409fe475434cd2125eee418517264a309.jpeg?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678334250&Signature=C7lXrC2ONf2q543jVhzC%2BY7zIs4%3D&validTime=1678334250368&resId=1461870139408385\",\"id_card_national\":\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/d8554251bd0947d39114ce40e4a616ce623919936221c20a2a2f4efe46622e48.jpeg?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678334249&Signature=SHmwat1NjK06zrTHwitULU7Vi58%3D&validTime=1678334249851&resId=1461870122631169\",\"id_card_name\":\"陈坤\",\"id_card_address\":\"上海市闵行区畹町路100弄1号401室\",\"id_card_number\":\"321022197711140014\",\"id_card_valid_time_begin\":\"2012-03-11\",\"id_card_valid_time\":\"2032-03-11\"},\"id_doc_info\":null,\"need_account_info\":true,\"account_info\":{\"bank_account_type\":\"74\",\"account_bank\":\"农业银行\",\"account_name\":\"杭州致民医药连锁有限公司\",\"bank_address_code\":\"330106\",\"bank_branch_id\":\"103331001114\",\"bank_name\":\"中国农业银行股份有限公司杭州美都广场支行\",\"account_number\":\"19011801040008383\"},\"contact_info\":{\"contact_type\":\"65\",\"contact_name\":\"陈坤\",\"contact_id_card_number\":\"321022197711140014\",\"mobile_phone\":\"18616506969\",\"contact_email\":\"kunchen@91jkys.com\"},\"sales_scene_info\":{\"store_name\":\"致民医药\",\"store_url\":null,\"store_qr_code\":\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/819f029a628a4512abec239f368569a3f712a0cd113eea6d05c42c715b5aa92d.jpg?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678432480&Signature=1ZoFEGf3tK287qHLqkUW52Mr0bs%3D&validTime=1678432480389&resId=1463518165336064\"},\"merchant_shortname\":\"杭州致民医药连锁有限公司\",\"qualifications\":\"[\\\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/c2807bfd489f4f4dba9c72eaa334a8e16a259ceff548c2ecb2bae7e69b68617e.png?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678334250&Signature=UDemY%2FjU7FgyY9fH62qqu3i0WPQ%3D&validTime=1678334250008&resId=1461870122631170\\\",\\\"https://91jkys-static-private.oss-cn-hangzhou.aliyuncs.com/attachment/pay-service/485b0c337a4647f5a753a1845690e94d0d4f464e95388329296ca65845e89481.png?OSSAccessKeyId=LTAI4G4z2zYtggDdQWk7G6yK&Expires=1678334250&Signature=Dc1iBKIgbvn7o9%2FcqwmKFnfhgaQ%3D&validTime=1678334250227&resId=1461870139408384\\\"]\",\"business_addition_pics\":null,\"business_addition_desc\":null,\"applyment_no\":\"J00001466185720692736\",\"sub_account_name\":\"杭州致民医药连锁有限公司\",\"sub_account_init_status\":2}";
        System.out.println(convert(str));

        String s = "\"{\\\"custId\\\":407939610582157,\\\"custName\\\":\\\"测试集团啊\\\",\\\"salerId\\\":590}\"";
        System.out.println(s);
        s = StringEscapeUtils.unescapeJava(s);
        System.out.println(s);
        s = s.replace("\"{", "{").replace("}\"", "}");
        System.out.println(s);
        CustomerUpdateMsgDTO customerUpdateMsgDTO = JSONObject.parseObject(s, CustomerUpdateMsgDTO.class);
        System.out.println(JSONObject.toJSONString(customerUpdateMsgDTO));
    }


    public final static void convert(Object json) {
        if (json instanceof JSONArray) {
            JSONArray arr = (JSONArray) json;
            for (Object obj : arr) {
                convert(obj);
            }
        } else if (json instanceof JSONObject) {
            JSONObject jo = (JSONObject) json;
            Set<String> keys = jo.keySet();
            String[] array = keys.toArray(new String[keys.size()]);
            for (String key : array) {
                Object value = jo.get(key);
                String[] key_strs = key.split("_");
                if (key_strs.length > 1) {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < key_strs.length; i++) {
                        String ks = key_strs[i];
                        if (!"".equals(ks)) {
                            if (i == 0) {
                                sb.append(ks);
                            } else {
                                int c = ks.charAt(0);
                                if (c >= 97 && c <= 122) {
                                    int v = c - 32;
                                    sb.append((char) v);
                                    if (ks.length() > 1) {
                                        sb.append(ks.substring(1));
                                    }
                                } else {
                                    sb.append(ks);
                                }
                            }
                        }
                    }
                    jo.remove(key);
                    jo.put(sb.toString(), value);
                }
                convert(value);
            }
        }
    }

    public final static Object convert(String json) {
        Object obj = JSON.parse(json);
        convert(obj);
        return obj;
    }


    static class CustomerUpdateMsgDTO {

        /**
         * 业务线id
         */
        private String bizId = "";
        /**
         * 客户id
         */
        private  Long custId;
        /**
         * 客户名称
         */
        private  String custName;
        /**
         * 负责销售id
         */
        private  Long salerId;


        public String getBizId() {
            return bizId;
        }

        public void setBizId(String bizId) {
            this.bizId = bizId;
        }

        public Long getCustId() {
            return custId;
        }

        public void setCustId(Long custId) {
            this.custId = custId;
        }

        public String getCustName() {
            return custName;
        }

        public void setCustName(String custName) {
            this.custName = custName;
        }

        public Long getSalerId() {
            return salerId;
        }

        public void setSalerId(Long salerId) {
            this.salerId = salerId;
        }
    }


}
